
import {Toast} from 'cube-ui'

let errorToast;

let correctToast;

let loadingToast;

/**
 * 加载Toast
 */
export function showLoadingToast() {
    loadingToast = Toast.$create(
        {
            txt: 'Loading...',
            mask: true,
            time:0
        }
    )
    loadingToast.show()
}



/**
 * 失败提示
 * @param error
 */
export function showErrorToast(error) {
    errorToast = Toast.$create({
        txt: error,
        type: 'error'
    })
    errorToast.show()
}

/**
 * 操作成功提示
 * @param txt
 */
export function showCorrectToast(txt) {
    correctToast = Toast.$create({
        txt: txt,
        type: 'correct'
    })
    correctToast.show()
}

/**
 * 隐藏所有的Toast
 */
export function hideToast() {
    if(loadingToast){
        loadingToast.hide()
    }
    if(correctToast){
        correctToast.hide()
    }
    if(errorToast){
        errorToast.hide()
    }
}

